clear
rng default
load U_CS
u1grid=U_CS(1,1); 
u0grid=0;
%% Grid 1
load IdSetM_final_grid1
IdSetM{1}=IdSetM_final_grid;
u2grid=linspace(U_CS(1,2)-10,U_CS(1,2)+10,60); 
u3grid=linspace(U_CS(1,3)-10,U_CS(1,3)+10,60); 
u4grid=linspace(U_CS(1,4)-10,U_CS(1,4)+10,60); 
[ca, cb, cc,cd, ce] = ndgrid(u0grid, u1grid, u2grid, u3grid, u4grid);
grid{1}=[ca(:) cb(:) cc(:) cd(:) ce(:)];

%% Grid 2
load IdSetM_final_grid2
IdSetM{2}=IdSetM_final_grid;
u2grid=linspace(U_CS(1,2)-20,U_CS(1,2)+20,60); 
u3grid=linspace(U_CS(1,3)-20,U_CS(1,3)+20,60); 
u4grid=linspace(U_CS(1,4)-20,U_CS(1,4)+20,60); 
[ca, cb, cc,cd, ce] = ndgrid(u0grid, u1grid, u2grid, u3grid, u4grid);
grid{2}=[ca(:) cb(:) cc(:) cd(:) ce(:)];

%% Grid 3
load IdSetM_final_grid3
IdSetM{3}=IdSetM_final_grid; 
u2grid=linspace(U_CS(1,2)-50,U_CS(1,2)+50,60); 
u3grid=linspace(U_CS(1,3)-50,U_CS(1,3)+50,60); 
u4grid=linspace(U_CS(1,4)-50,U_CS(1,4)+50,60); 
[ca, cb, cc,cd, ce] = ndgrid(u0grid, u1grid, u2grid, u3grid, u4grid);
grid{3}=[ca(:) cb(:) cc(:) cd(:) ce(:)];

%% Grid 4
load IdSetM_final_grid4
IdSetM{4}=IdSetM_final_grid;
u2grid=linspace(U_CS(1,2)-100,U_CS(1,2)+100,60); 
u3grid=linspace(U_CS(1,3)-100,U_CS(1,3)+100,60); 
u4grid=linspace(U_CS(1,4)-100,U_CS(1,4)+100,60); 
[ca, cb, cc,cd, ce] = ndgrid(u0grid, u1grid, u2grid, u3grid, u4grid);
grid{4}=[ca(:) cb(:) cc(:) cd(:) ce(:)];

%% Grid 5
load IdSetM_final_grid5
IdSetM{5}=IdSetM_final_grid;
u2grid=linspace(U_CS(1,2)-300,U_CS(1,2)+300,60); 
u3grid=linspace(U_CS(1,3)-300,U_CS(1,3)+300,60); 
u4grid=linspace(U_CS(1,4)-300,U_CS(1,4)+300,60); 
[ca, cb, cc,cd, ce] = ndgrid(u0grid, u1grid, u2grid, u3grid, u4grid);
grid{5}=[ca(:) cb(:) cc(:) cd(:) ce(:)];

%% Grid 6
load IdSetM_final_grid6
IdSetM{6}=IdSetM_final_grid;
u2grid=linspace(U_CS(1,2)-500,U_CS(1,2)+500,60); 
u3grid=linspace(U_CS(1,3)-500,U_CS(1,3)+500,60); 
u4grid=linspace(U_CS(1,4)-500,U_CS(1,4)+500,60); 
[ca, cb, cc,cd, ce] = ndgrid(u0grid, u1grid, u2grid, u3grid, u4grid);
grid{6}=[ca(:) cb(:) cc(:) cd(:) ce(:)];

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%% Projections in two dimensions %%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x=1;
alpha=[0 0.2 0.4 0.5 0.5 0.5];
    %u21 u31
    figure
    for f=1:6
    h=7-f;
    M=unique([grid{h}(:,3) grid{h}(:,4)], 'rows', 'stable'); 
    scatter(M(:,1), M(:,2), 5,[0.1+alpha(h) 0.1+alpha(h) 0.1+alpha(h)], 'filled')
    hold on
    M=unique([IdSetM{h}(:,3) IdSetM{h}(:,4)], 'rows', 'stable'); 
    scatter(M(:,1), M(:,2), 5,'b', 'filled')
    hold on
    end
    scatter(U_CS(x,2), U_CS(x,3), 30,'r', 'filled')
    hold off
    xlabel(sprintf('U_{%d2}',x),'FontSize', 25) 
    ylabel(sprintf('U_{%d3}',x),'FontSize', 25)
    xlim([-500 500])
    ylim([-500 500])
    box on
    set(gca, 'ytick',[-500 0 500],'xtick',[-500 0 500],'FontSize',20)
    saveas(gcf,sprintf('U_%d2_%d3.jpg',x,x))
    
    %u21 u41
    figure
    for f=1:6
    h=7-f;
    M=unique([grid{h}(:,3) grid{h}(:,5)], 'rows', 'stable'); 
    scatter(M(:,1), M(:,2), 5,[0.1+alpha(h) 0.1+alpha(h) 0.1+alpha(h)], 'filled')
    hold on
    M=unique([IdSetM{h}(:,3) IdSetM{h}(:,5)], 'rows', 'stable'); 
    scatter(M(:,1), M(:,2), 5,'b', 'filled')
    hold on
    end
    scatter(U_CS(x,2), U_CS(x,4), 30,'r', 'filled')
    hold off
    xlabel(sprintf('U_{%d2}',x),'FontSize', 25) 
    ylabel(sprintf('U_{%d4}',x),'FontSize', 25)
    xlim([-500 500])
    ylim([-500 500])
    box on
    set(gca, 'ytick',[-500 0 500],'xtick',[-500 0 500],'FontSize',20)
    saveas(gcf,sprintf('U_%d2_%d4.jpg',x,x))
    
 
   







